Pragmatic Python Programming by Gabor Guta

Pragmatic Python Programming by Gabor Guta

Author:Gabor Guta
Language: eng
Format: epub
ISBN: 9781484281529
Publisher: Apress


Listing 4-7 while statement with a Status Variable

The assignment expression (alias walrus expression) was introduced in Python 3.8, and it provides an elegant solution to the issue shown earlier. In Listing 4-8 the assignment of the level of discount located in the expression guards the while loop. The code will be more transparent; therefore, the same value giving the statement will not have to be repeated in two places or have not have to introduce a new variable to delay the evaluation of the condition.product = Product('K01', 'cube', 1000)

while not 0 < (discount_value

:= int(input('Amount of the discount (in %)?'))) <= 99:

print('Discount abount is too low or too high')

product.reduce_price(discount_value)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.